<div class="opwindow">
	<form name="theform2" id="theform2" method="post" action="{echo \befen\get_url()}">
		<div class="layui-tab layui-tab-brief">
			<ul class="layui-tab-title">
				<li class="layui-this">微信</li>
				<li>支付宝</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<div class="layui-form">
						<table class="layui-table">
							<tbody>
								<tr>
									<td class="td1">默认费率</td>
									<td class="td2"><input type="text" name="trade_rates" id="trade_rates" class="layui-input layui-disabled" value="{$value[trade_rates]}" disabled placeholder=""></td>
								</tr>
								<tr>
									<td class="td1">通道状态</td>
									<td class="td2" style="width:30%;">
										<select name="status_weixin" id="status_weixin" class="layui-select">
											<option value="1" <!--{if 1 == $value['status_weixin']}-->selected<!--{/if}-->>开启</option>
											<option value="0" <!--{if 0 == $value['status_weixin']}-->selected<!--{/if}-->>禁用</option>
										</select>
									</td>
								</tr>
								<tr>
									<td class="td1">选择通道</td>
									<td class="td2" style="width:30%;">
										<select name="gate_weixin" id="gate_weixin" class="layui-select" lay-filter="select_weixin">
											<option value="0">直连</option>
											<!--{loop $gate_list $val}-->
											<option value="{$val[sub_key]}" <!--{if $val['sub_key'] == $value['gate_weixin']}-->selected<!--{/if}-->>{$val[sub_name]}</option>
											<!--{/loop}-->
										</select>
									</td>
								</tr>
								<tr class="tr_weixin" <!--{if $value['gate_weixin']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">子商户号</td>
									<td class="td2"><input type="text" name="sub_mch_id" id="sub_mch_id" class="layui-input" value="{$value[sub_mch_id]}" placeholder=""></td>
								</tr>
								<tr class="tr_weixin0" style="display:none;" <!--{if $value['gate_weixin']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">交易费率</td>
									<td class="td2"><input type="text" name="rates_weixin" id="rates_weixin" class="layui-input" value="{$value[rates_weixin]}" placeholder=""></td>
								</tr>
								<tr class="tr_weixin_sub_gate" <!--{if !$value['gate_weixin']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">商户编号</td>
									<td class="td2"><input type="text" name="weixin_sub_mch_no" id="weixin_sub_mch_no" class="layui-input" value="" placeholder=""></td>
								</tr>
								<tr class="tr_weixin_sub_gate0" style="display:none;" <!--{if !$value['gate_weixin']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">交易费率</td>
									<td class="td2"><input type="text" name="weixin_trade_rates" id="weixin_trade_rates" class="layui-input" value="" placeholder=""></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-tab-item">
					<div class="layui-form">
						<table class="layui-table">
							<tbody>
								<tr>
									<td class="td1">默认费率</td>
									<td class="td2"><input type="text" name="trade_rates" id="trade_rates" class="layui-input layui-disabled" value="{$value[trade_rates]}" disabled placeholder=""></td>
								</tr>
								<tr>
									<td class="td1">通道状态</td>
									<td class="td2">
										<select name="status_alipay" id="status_alipay" class="layui-select">
											<option value="1" <!--{if 1 == $value['status_alipay']}-->selected<!--{/if}-->>开启</option>
											<option value="0" <!--{if 0 == $value['status_alipay']}-->selected<!--{/if}-->>禁用</option>
										</select>
									</td>
								</tr>
								<tr>
									<td class="td1">选择通道</td>
									<td class="td2">
										<select name="gate_alipay" id="gate_alipay" class="layui-select" lay-filter="select_alipay">
											<option value="0">直连</option>
											<!--{loop $gate_list $val}-->
											<option value="{$val[sub_key]}" <!--{if $val['sub_key'] == $value['gate_alipay']}-->selected<!--{/if}-->>{$val[sub_name]}</option>
											<!--{/loop}-->
										</select>
									</td>
								</tr>
								<tr class="tr_alipay" <!--{if $value['gate_alipay']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">授权令牌</td>
									<td class="td2"><input type="text" name="app_auth_token" id="app_auth_token" class="layui-input" value="{$value[app_auth_token]}" placeholder=""></td>
								</tr>
								<tr class="tr_alipay0" style="display:none;" <!--{if $value['gate_alipay']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">交易费率</td>
									<td class="td2"><input type="text" name="rates_alipay" id="rates_alipay" class="layui-input" value="{$value[rates_alipay]}" placeholder=""></td>
								</tr>
								<tr class="tr_alipay_sub_gate" <!--{if !$value['gate_alipay']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">商户编号</td>
									<td class="td2"><input type="text" name="alipay_sub_mch_no" id="alipay_sub_mch_no" class="layui-input" value="" placeholder=""></td>
								</tr>
								<tr class="tr_alipay_sub_gate0" style="display:none;" <!--{if !$value['gate_alipay']}-->style="display:none;"<!--{/if}-->>
									<td class="td1">交易费率</td>
									<td class="td2"><input type="text" name="alipay_trade_rates" id="alipay_trade_rates" class="layui-input" value="" placeholder=""></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
			<div class="layui-form-item" style="margin-top:-10px;">
				<div class="layui-col layui-col-md12" style="text-align:center;">
					<button type="button" id="cancel2" class="layui-btn layui-btn-primary">取消</button>
					<button type="submit" name="submit2" value="submit2" id="submit2" class="layui-btn">提交</button>
				</div>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
init_Form();
$("#cancel2").click(function(){
	layer.close(index_window);
});
$("#submit2").click(function(){
	ajaxSubmit(this, "", "#theform2");
});
var merchant_id = "{echo input('param.merchant_id')}";
function get_sub_gate(cur_gate, sub_gate) {
	$.ajax({
		type: "POST",
		dataType: "json",
		cache: false,
		timeout: 10000,
		url: "{echo url('merchant/get_sub_gate')}",
		data: {
			ajax: "json",
			merchant_id: merchant_id,
			sub_gate: sub_gate,
		},
		success: function(data){
			$("#" + cur_gate + "_sub_mch_no").val(data.contents.sub_mch_no);
			$("#" + cur_gate + "_trade_rates").val(get_rates(data.contents.trade_rates));
		},
		error: function(xhr, status){
			console.log(status);
			console.log(xhr);
			showAlert("获取商户信息失败");
		},
		complete: function(){
			hideLoader();
		},
		beforeSend: function(){
			showLoader();
		}
	});
}
$(document).ready(function(){
	var rates_alipay = get_rates($("#rates_alipay").val());
	var rates_weixin = get_rates($("#rates_weixin").val());
	$("#rates_alipay").val(rates_alipay);
	$("#rates_weixin").val(rates_weixin);
	$("#gate_weixin").val() != "0" && get_sub_gate("weixin", $("#gate_weixin").val());
	$("#gate_alipay").val() != "0" && get_sub_gate("alipay", $("#gate_alipay").val());
});
layui.use('form', function(){
	var form = layui.form;
	form.on('select(select_weixin)', function(data){
		//console.log(data.value);
		var value = data.value;
		if(value == "0") {
			$(".tr_weixin").show();
			$(".tr_weixin_sub_gate").hide();
			$("#weixin_sub_mch_no").val("");
			$("#weixin_trade_rates").val("");
		} else {
			$(".tr_weixin").hide();
			$(".tr_weixin_sub_gate").show();
			get_sub_gate("weixin", data.value);
		}
	}); 
	form.on('select(select_alipay)', function(data){
		//console.log(data.value);
		var value = data.value;
		if(value == "0") {
			$(".tr_alipay").show();
			$(".tr_alipay_sub_gate").hide();
			$("#alipay_sub_mch_no").val("");
			$("#alipay_trade_rates").val("");
		} else {
			$(".tr_alipay").hide();
			$(".tr_alipay_sub_gate").show();
			get_sub_gate("alipay", data.value);
		}
	});
});
</script>
